//
//  PackageSKUDataHelper.m
//  BaseProject
//
//  Created by 王洋 on 2021/5/18.
//  Copyright © 2021 王洋. All rights reserved.
//

#import "PackageSKUDataHelper.h"

@implementation PackageSKUDataHelper

+ (NSArray *)cacheSKUDataSourceWithModel:(CommonPackageModel *)model {

    NSMutableArray *dataSource = @[].mutableCopy;
    
    if (model.autoCarSpecsVo.headCarList.count > 0) {
        NSMutableDictionary *headDic = @{}.mutableCopy;
        [headDic setValue:@"头车" forKey:@"name"];
        NSMutableArray *values = @[].mutableCopy;
        for (WeddingCarSKUModel *skuModel in model.autoCarSpecsVo.headCarList) {
            [values addObject:skuModel.specName];
        }
        [headDic setValue:values forKey:@"value"];
        [dataSource addObject:headDic];
    }
    
    if (model.autoCarSpecsVo.followCarList.count > 0) {
        NSMutableDictionary *headDic = @{}.mutableCopy;
        [headDic setValue:@"跟车" forKey:@"name"];
        NSMutableArray *values = @[].mutableCopy;
        for (WeddingCarSKUModel *skuModel in model.autoCarSpecsVo.followCarList) {
            [values addObject:skuModel.specName];
        }
        [headDic setValue:values forKey:@"value"];
        [dataSource addObject:headDic];
    }
    
    if (model.autoCarSpecsVo.userTimeList.count > 0) {
        NSMutableDictionary *headDic = @{}.mutableCopy;
        [headDic setValue:@"用时" forKey:@"name"];
        NSMutableArray *values = @[].mutableCopy;
        for (WeddingCarSKUModel *skuModel in model.autoCarSpecsVo.userTimeList) {
            [values addObject:skuModel.specName];
        }
        [headDic setValue:values forKey:@"value"];
        [dataSource addObject:headDic];
    }
    
    
    if (model.autoCarSpecsVo.userMileageList.count > 0) {
        NSMutableDictionary *headDic = @{}.mutableCopy;
        [headDic setValue:@"里程" forKey:@"name"];
        NSMutableArray *values = @[].mutableCopy;
        for (WeddingCarSKUModel *skuModel in model.autoCarSpecsVo.userMileageList) {
            [values addObject:skuModel.specName];
        }
        [headDic setValue:values forKey:@"value"];
        [dataSource addObject:headDic];
    }
    
    if (model.autoCarSpecsVo.colorList.count > 0) {
        NSMutableDictionary *headDic = @{}.mutableCopy;
        [headDic setValue:@"颜色" forKey:@"name"];
        NSMutableArray *values = @[].mutableCopy;
        for (WeddingCarSKUModel *skuModel in model.autoCarSpecsVo.colorList) {
            [values addObject:skuModel.specName];
        }
        [headDic setValue:values forKey:@"value"];
        [dataSource addObject:headDic];
    }
    


    
    return dataSource;
}

+ (NSArray *)cacheSKUDataWithModel:(CommonPackageModel *)model {
    
    NSMutableArray *skuData = @[].mutableCopy;

    for (WeddingCarSpecModel *conditionModel in model.sellerGoodsCarSpecsList) {
        
        NSMutableDictionary *conditionDic = @{}.mutableCopy;
                
        NSString *conditionStr = conditionModel.specName;
        conditionStr =[conditionStr stringByReplacingOccurrencesOfString:@" " withString:@""];
        conditionStr =[conditionStr stringByReplacingOccurrencesOfString:@"/" withString:@","];

        [conditionDic setValue:conditionStr forKey:@"contition"];
        [conditionDic setValue:@"1" forKey:@"price"];
        [conditionDic setValue:conditionModel.sgcsId forKey:@"store"];
        [conditionDic setValue:conditionModel.sgcsId forKey:@"sgcsId"];
        [skuData addObject:conditionDic];
    }
    
    NSLog(@"%@",skuData);
    
    return skuData;
}

+ (NSMutableArray <CommonSelSkuModel*>*)matchingSkuListFromModel:(CommonPackageModel *)model withString:(NSString *)str {
    NSMutableArray <CommonSelSkuModel*>* array = @[].mutableCopy;
    
    //根据spcname匹配数组userShoppingCarDetailList
    NSArray *items = [str componentsSeparatedByString:@" / "];

    //这里只是为了解决提交订单页面的sku列表显示
    //当多组sku里面显示的文字一样的时候，可能会出错
    for (NSString *str in items) {
        
        for (WeddingCarSKUModel *skuModel in model.autoCarSpecsVo.headCarList) {
            if ([skuModel.specName isEqualToString:str]) {
                CommonSelSkuModel *selSku = [[CommonSelSkuModel alloc] init];
                selSku.specName = skuModel.specName;
                selSku.specAttribute = [skuModel.specAttribute integerValue];
                [array addObject:selSku];
                break;
            }
        }
        
        for (WeddingCarSKUModel *skuModel in model.autoCarSpecsVo.followCarList) {
            if ([skuModel.specName isEqualToString:str]) {
                CommonSelSkuModel *selSku = [[CommonSelSkuModel alloc] init];
                selSku.specName = skuModel.specName;
                selSku.specAttribute = [skuModel.specAttribute integerValue];
                [array addObject:selSku];
                break;
            }
        }
        
        for (WeddingCarSKUModel *skuModel in model.autoCarSpecsVo.userTimeList) {
            if ([skuModel.specName isEqualToString:str]) {
                CommonSelSkuModel *selSku = [[CommonSelSkuModel alloc] init];
                selSku.specName = skuModel.specName;
                selSku.specAttribute = [skuModel.specAttribute integerValue];
                [array addObject:selSku];
                break;
            }
        }
        
        for (WeddingCarSKUModel *skuModel in model.autoCarSpecsVo.userMileageList) {
            if ([skuModel.specName isEqualToString:str]) {
                CommonSelSkuModel *selSku = [[CommonSelSkuModel alloc] init];
                selSku.specName = skuModel.specName;
                selSku.specAttribute = [skuModel.specAttribute integerValue];
                [array addObject:selSku];
                break;
            }
        }
        
        for (WeddingCarSKUModel *skuModel in model.autoCarSpecsVo.colorList) {
            if ([skuModel.specName isEqualToString:str]) {
                CommonSelSkuModel *selSku = [[CommonSelSkuModel alloc] init];
                selSku.specName = skuModel.specName;
                selSku.specAttribute = [skuModel.specAttribute integerValue];
                [array addObject:selSku];
                break;
            }
        }
    }
    
    NSMutableArray *resultArrM = @[].mutableCopy;
    for (CommonSelSkuModel *item in array) {
        if (![resultArrM containsObject:item]) {
          [resultArrM addObject:item];
        }
    }

    return resultArrM;
}

/*
 NSArray *dataSource = @[@{@"name" : @"头车",
                           @"value" : @[@"宝马X7", @"保时捷卡宴"]},
                         @{@"name" : @"跟车",
                           @"value" : @[@"奥拓", @"江淮和悦", @"大众桑塔纳"]},
                         @{@"name" : @"颜色",
                           @"value" : @[@"高端黑", @"高端银", @"珍珠白", @"典雅白"]},
                         @{@"name" : @"使用时长",
                           @"value" : @[@"全天", @"半天"]}];
 */

/*
 _skuData = @[
              @{@"contition":@"宝马X7,奥拓,高端银,全天",
                @"price":@"1120",
                @"store":@"167"},
              @{@"contition":@"宝马X7,奥拓,典雅白,全天",
                @"price":@"1200",
                @"store":@"289"},
              @{@"contition":@"宝马X7,江淮和悦,珍珠白,全天",
                @"price":@"889",
                @"store":@"300"},
              @{@"contition":@"宝马X7,江淮和悦,典雅白,全天",
                @"price":@"991",
                @"store":@"178"},
              @{@"contition":@"保时捷卡宴,奥拓,高端银,全天",
                @"price":@"1000",
                @"store":@"200"},
              @{@"contition":@"保时捷卡宴,大众桑塔纳,珍珠白,全天",
                @"price":@"880",
                @"store":@"12"},
              @{@"contition":@"保时捷卡宴,大众桑塔纳,高端黑,全天",
                @"price":@"1210",
                @"store":@"300"},
              @{@"contition":@"宝马X7,大众桑塔纳,珍珠白,半天",
                @"price":@"888",
                @"store":@"121"},
              @{@"contition":@"保时捷卡宴,江淮和悦,典雅白,半天",
                @"price":@"1288",
                @"store":@"125"},
              @{@"contition":@"宝马X7,大众桑塔纳,珍珠白,全天",
                @"price":@"1210",
                @"store":@"123"}
              ];
 */

@end
